﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Erp.Migrations
{
    /// <inheritdoc />
    public partial class add_table_MaterialWhses : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "SafeStock",
                schema: "Erp",
                table: "MaterialInfos");

            migrationBuilder.DropColumn(
                name: "Unt",
                schema: "Erp",
                table: "MaterialInfos");

            migrationBuilder.AddColumn<string>(
                name: "Aprvno",
                schema: "Erp",
                table: "MaterialInfos",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<int>(
                name: "PacCnt",
                schema: "Erp",
                table: "MaterialInfos",
                type: "integer",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<string>(
                name: "PacuntCodg",
                schema: "Erp",
                table: "MaterialInfos",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "PacuntName",
                schema: "Erp",
                table: "MaterialInfos",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "ProdentpName",
                schema: "Erp",
                table: "MaterialInfos",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "SaluntUntCodg",
                schema: "Erp",
                table: "MaterialInfos",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "SaluntUntName",
                schema: "Erp",
                table: "MaterialInfos",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.CreateTable(
                name: "InboundRecs",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    OrderNo = table.Column<string>(type: "text", nullable: false),
                    InWarehouseType = table.Column<int>(type: "integer", nullable: false),
                    WarehouseId = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialWhseCodg = table.Column<string>(type: "text", nullable: false),
                    MaterialWhseName = table.Column<string>(type: "text", nullable: false),
                    SupplierCodg = table.Column<string>(type: "text", nullable: false),
                    SupplierName = table.Column<string>(type: "text", nullable: false),
                    InboundStas = table.Column<int>(type: "integer", nullable: false),
                    InvoiceNo = table.Column<string>(type: "text", nullable: true),
                    DiscountRate = table.Column<decimal>(type: "numeric(18,2)", nullable: true),
                    PurchaseTotal = table.Column<decimal>(type: "numeric(18,4)", nullable: true),
                    DiscountTotal = table.Column<decimal>(type: "numeric(18,4)", nullable: true),
                    TotalRetailTotal = table.Column<decimal>(type: "numeric(18,4)", nullable: true),
                    BillingDateTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    PurchaseDateTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    ReviewTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    ReviewerValue = table.Column<string>(type: "text", nullable: true),
                    ReviewerName = table.Column<string>(type: "text", nullable: true),
                    ArrivalDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    AcceptanceDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    AcceptanceOpertorValue = table.Column<string>(type: "text", nullable: true),
                    AcceptanceOpertorLabel = table.Column<string>(type: "text", nullable: true),
                    EntryOpertorValue = table.Column<string>(type: "text", nullable: true),
                    EntryOpertorLabel = table.Column<string>(type: "text", nullable: true),
                    EntryDateTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    ExtensionData = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_InboundRecs", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MaterialSuppliers",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    SupplierCatgeCodg = table.Column<string>(type: "text", nullable: false),
                    SupplierCatgeName = table.Column<string>(type: "text", nullable: false),
                    SupplierCodg = table.Column<string>(type: "text", nullable: false),
                    SupplierName = table.Column<string>(type: "text", nullable: false),
                    Pinyincode = table.Column<string>(type: "text", nullable: true),
                    Wubicode = table.Column<string>(type: "text", nullable: true),
                    SplerPmtno = table.Column<string>(type: "text", nullable: true),
                    Contacts = table.Column<string>(type: "text", nullable: true),
                    EMail = table.Column<string>(type: "text", nullable: true),
                    Telephone = table.Column<string>(type: "text", nullable: true),
                    Bank = table.Column<string>(type: "text", nullable: true),
                    LegalRepresentative = table.Column<string>(type: "text", nullable: true),
                    ValiFlag = table.Column<bool>(type: "boolean", nullable: false),
                    DutyParagraph = table.Column<string>(type: "text", nullable: true),
                    Region = table.Column<string>(type: "text", nullable: true),
                    BusinessTypeCode = table.Column<string>(type: "text", nullable: true),
                    BusinessTypeName = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MaterialSuppliers", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MaterialWhses",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialWhseCodg = table.Column<string>(type: "text", nullable: false),
                    MaterialWhseName = table.Column<string>(type: "text", nullable: false),
                    Pinyincode = table.Column<string>(type: "text", nullable: true),
                    Wubicode = table.Column<string>(type: "text", nullable: true),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    Descr = table.Column<string>(type: "text", nullable: true),
                    DeptCode = table.Column<string>(type: "text", nullable: false),
                    DeptName = table.Column<string>(type: "text", nullable: false),
                    ValiFlag = table.Column<bool>(type: "boolean", nullable: false),
                    PatientId = table.Column<Guid>(type: "uuid", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    MaterialWhseId = table.Column<Guid>(type: "uuid", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MaterialWhses", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MaterialWhses_MaterialWhses_MaterialWhseId",
                        column: x => x.MaterialWhseId,
                        principalSchema: "Erp",
                        principalTable: "MaterialWhses",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "InboundRecDetls",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    InboundRecId = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialInfoCodg = table.Column<string>(type: "text", nullable: false),
                    MaterialInfoName = table.Column<string>(type: "text", nullable: false),
                    PurchaseUnitPrice = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    PurchaseQuantity = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    PurchaseAmount = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    DiscountRate = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    DiscountUnitPrice = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    DiscountAmount = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    RetailPrice = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    RetailAmount = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    ManuLotnum = table.Column<string>(type: "text", nullable: false),
                    ManufactureDateTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    ValidityDateTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    BatchNumber = table.Column<string>(type: "text", nullable: false),
                    InboundStas = table.Column<int>(type: "integer", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_InboundRecDetls", x => x.Id);
                    table.ForeignKey(
                        name: "FK_InboundRecDetls_InboundRecs_InboundRecId",
                        column: x => x.InboundRecId,
                        principalSchema: "Erp",
                        principalTable: "InboundRecs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_InboundRecDetls_InboundRecId",
                schema: "Erp",
                table: "InboundRecDetls",
                column: "InboundRecId");

            migrationBuilder.CreateIndex(
                name: "IX_MaterialWhses_MaterialWhseId",
                schema: "Erp",
                table: "MaterialWhses",
                column: "MaterialWhseId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "InboundRecDetls",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "MaterialSuppliers",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "MaterialWhses",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "InboundRecs",
                schema: "Erp");

            migrationBuilder.DropColumn(
                name: "Aprvno",
                schema: "Erp",
                table: "MaterialInfos");

            migrationBuilder.DropColumn(
                name: "PacCnt",
                schema: "Erp",
                table: "MaterialInfos");

            migrationBuilder.DropColumn(
                name: "PacuntCodg",
                schema: "Erp",
                table: "MaterialInfos");

            migrationBuilder.DropColumn(
                name: "PacuntName",
                schema: "Erp",
                table: "MaterialInfos");

            migrationBuilder.DropColumn(
                name: "ProdentpName",
                schema: "Erp",
                table: "MaterialInfos");

            migrationBuilder.DropColumn(
                name: "SaluntUntCodg",
                schema: "Erp",
                table: "MaterialInfos");

            migrationBuilder.DropColumn(
                name: "SaluntUntName",
                schema: "Erp",
                table: "MaterialInfos");

            migrationBuilder.AddColumn<decimal>(
                name: "SafeStock",
                schema: "Erp",
                table: "MaterialInfos",
                type: "numeric",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Unt",
                schema: "Erp",
                table: "MaterialInfos",
                type: "text",
                nullable: true);
        }
    }
}
